/*
 * @Author: dmyang
 * @Date:   2015-08-31 21:17:45
 * @Last Modified by:   dmyang
 * @Last Modified time: 2016-03-28 09:48:22
 */

'use strict'

import 'commonCss'



// 直接使用npm模块

require('../css/main.css')
require('../css/swiper.min.css')
require('../js/lib/swiper.min.js')

let report = require('./helpers/report')
let bar = require('./helpers/bar')
let url = require('./utils/url')
let $ajax = require('./helpers/ajax')
require('./utils/site')

let tpl = site.tpl('main')

let name = site.QueryString('type')


window.toGo = function(type) {
    let sort = (type=='prev'?'desc':'asc')
    let id = site.QueryString('id')
    site._ajax({
        type: 'GET',
        url: HTTP_SERVER + 'information/api/information/' + id+'/next'+'?sort='+sort,
        data: {},
        success: function (res) {
            if(!res.content){
                return
            }
            let banner = [
                {image: 'http://ocpshpa2y.bkt.clouddn.com/sdly/banner/img_03.jpg', url: ''},
            ]
            tpl({banner: banner, type: site.type, id: id,res:res})
            site.banner(banner)
        }
    })
}

function handler () {
    site.getToken(render)
}

function render(){
    site.setNav(main)
    site.header()
    site._ajax({
        type:'GET',
        url: HTTP_SERVER + 'cms/api/websites/89060613317206016',
        data:{},
        success: function (res) {
            site.footer(res)
        }
    })
}
site.render = main
function main () {
    let id = site.QueryString('id')
    let ind = site.getInd(id)
    if(id=='88282119339511808'){
        let banner = [
            {image: site.imagePath+'banner/banner8.jpg', url: ''},
        ]
        tpl({banner: banner, type: site.type, id: id,res:{}})
        site.banner(banner)
        site.menuHide()

    }else {
        site._ajax({
            type: 'GET',
            url: HTTP_SERVER + 'information/api/information/' + id,
            data: {},
            success: function (res) {
                site.banner('108263253079019520',{type: site.type, id: id,res:res})
                site.menuHide()
                site.share({
                    desc: res.description, // 分享描述
                    title: res.name, // 分享标题
                    link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: res.image, // 分享图标
                })

            }
        })
    }
}

document.addEventListener('visibilitychange', handler)
window.addEventListener('DOMContentLoaded', handler)
window.addEventListener('resize', handler)





